package com.nhjf.component.job;
 
import java.util.ArrayList;
import java.util.List;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
 
import com.nhjf.common.util.Properties.SysProperties;
import com.nhjf.component.task.ElectronicCodeTask;
import com.nhjf.component.task.QuartzTask;

 
 
/**
 * @类功能说明：定时任务初始化
 * @类修改者：
 */
@Component
public class QuartzJobInit implements InitializingBean {
    
    private final static Logger logger = LoggerFactory.getLogger(QuartzJobInit.class);
     
    public void init() {
        
        List<QuartzTask> taskList = new ArrayList<QuartzTask>();
        

        
        //延时发送电子码
        ElectronicCodeTask electronicCodeTask = new ElectronicCodeTask();
        electronicCodeTask.setTaskName("定时任务");
        electronicCodeTask.setGroupName("定时器");
        electronicCodeTask.setCronExpression(SysProperties.getInstance().get("electronicCodeTask"));
//        //zzq add 2015-11-08 定时检查商品水印相关信息
        /*
        ProductWaterMarkStartTask waterMarkStartTask  = new ProductWaterMarkStartTask();
        waterMarkStartTask.setTaskName("商品水印开始启动任务");
        waterMarkStartTask.setGroupName("明珠商城定时器");
        waterMarkStartTask.setCronExpression(SysProperties.getInstance().get("watermarkDate"));
 
    
        ProductWaterMarkEndTask waterMarkEndTask  = new ProductWaterMarkEndTask();
        waterMarkEndTask.setTaskName("商品水印结束启动任务");
        waterMarkEndTask.setGroupName("明珠商城定时器");
        waterMarkEndTask.setCronExpression(SysProperties.getInstance().get("watermarkDate"));
 
        
        //检查特惠活动开始的定时任务
        ProductThActiveStartTask productThActiveStartTask = new ProductThActiveStartTask();
        productThActiveStartTask.setTaskName("特惠活动开始的定时任务");
        productThActiveStartTask.setGroupName("明珠商城定时器");
        productThActiveStartTask.setCronExpression(SysProperties.getInstance().get("teiHuiDate"));
        
        //检查特惠活动结束的定时任务
        ProductThActiveEndTask productThActiveEndTask = new ProductThActiveEndTask();
        productThActiveEndTask.setTaskName("特惠活动结束的定时任务");
        productThActiveEndTask.setGroupName("明珠商城定时器");
        productThActiveEndTask.setCronExpression(SysProperties.getInstance().get("teiHuiDate"));
    
        
        //检查买就赠活动
        ProductPreActiveStartTask productPreActiveStartTask = new ProductPreActiveStartTask();
        productPreActiveStartTask.setTaskName("买就赠活动开始的定时任务");
        productPreActiveStartTask.setGroupName("明珠商城定时器");
        productPreActiveStartTask.setCronExpression(SysProperties.getInstance().get("checkPresentDate"));
        
        ProductPreActiveEndTask productPreActiveEndTask = new ProductPreActiveEndTask();
        productPreActiveEndTask.setTaskName("买就赠活动结束的定时任务");
        productPreActiveEndTask.setGroupName("明珠商城定时器");
        productPreActiveEndTask.setCronExpression(SysProperties.getInstance().get("checkPresentDate"));
        //*/
//            
        taskList.add(electronicCodeTask);
//        taskList.add(QuestionnaireExpiredTask);
//        taskList.add(productSaleActiveStartTask);
//        taskList.add(productSaleActiveEndTask);
//        taskList.add(electronicCodeTask);
//        taskList.add(productTask);        
//        taskList.add(ticketCouponTask);
//        taskList.add(ticketProduct);
//        taskList.add(electronicCodeSendPrescription);
        if (taskList.size() == 0){
            return;
        }
        for (QuartzTask task : taskList) {
            try {
                logger.info("添加定时任务" + task.getTaskName());
                QuartzJobManager.getInstance().addTask(task);
            } catch (Exception e) {
                logger.error(e.getMessage());
                e.printStackTrace();
            }
        }
    }
 
    @Override
    public void afterPropertiesSet() throws Exception {
        init();
    }
 
}